/*
 * @lc app=leetcode.cn id=1624 lang=javascript
 *
 * [1624] 两个相同字符之间的最长子字符串
 */

// @lc code=start
/**
 * @param {string} s
 * @return {number}
 */
var maxLengthBetweenEqualCharacters = function (s) {
  const map = new Map();
  let max = -1;
  s.split('').forEach((ch, index) => {
    if (map.has(ch)) {
      max = Math.max(max, index - map.get(ch) - 1);
    } else {
      map.set(ch, index);
    }
  })
  return max;
};
// @lc code=end

